package cn.edu.leetcode.其他;

import java.util.Locale;

public class 验证回文串 {

    public static void main(String[] args) {
        System.out.println(isPalindrome("A man, a plan, a canal: Panama"));
    }


    public static boolean isPalindrome(String s) {

        String s1 = s.toLowerCase();
        for (int i = 0, j = s1.length()-1; i < j; i++, j--) {
            while (!Character.isLetterOrDigit(s1.charAt(i))) {
                i++;
                if (i >= j) return true;
            }
            while (!Character.isLetterOrDigit(s1.charAt(j))) {
                j--;
                if (i >= j) return true;
            }

            if (s1.charAt(i) != s1.charAt(j)) return false;
        }

        return true;
    }
}
